<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.sql.*"%>
<%@page import="deweb.cimaplanning.misc"%>


<%@page import="deweb.cimaplanning.reports.corn_position.Report"%>
<%@page import="deweb.cimaplanning.reports.corn_position.MonthlyPeriod"%>
<%@page import="deweb.cimaplanning.reports.corn_position.Transports"%>
<%@page import="deweb.cimaplanning.reports.corn_position.PurchaseOrder"%>
<%@page import="deweb.cimaplanning.reports.corn_position.Futures"%>
<%@page import="java.util.ArrayList"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/principal.css" type="text/css">
<link rel="stylesheet" href="../css/secundario.css" type="text/css">
<title>Reporte de Posición de Maíz</title>
</head>
<body>
<%

boolean DEBUG = true;
if (DEBUG) out.println("<br>DEBUG ON: [" + request.getRequestURI() + "]");

com.deweb.GetProperties prop;
Connection conn = null;
Statement stmt  = null;
ResultSet rs	= null;
String sql 		= null;

try{
    prop = new com.deweb.GetProperties(request);
    conn = prop.getDBConnection();
    stmt = conn.createStatement();
	
	sql = "";
	
	String keyId	= request.getParameter("keyId") == null ? "" : request.getParameter("keyId");
	int frmAction	= request.getParameter("frmAction") == null ? 0 : (request.getParameter("frmAction").toString().length() == 0 ? 0 : Integer.parseInt(request.getParameter("frmAction").toString()));
	boolean print	= request.getParameter("print") == null ? false : (request.getParameter("print").toString().equals("1") ? true : false);
	
	int order	= request.getParameter("order") == null ? 1 : (request.getParameter("order").toString().length() == 0 ? 1 : Integer.parseInt(request.getParameter("order").toString()));
	String dir	= request.getParameter("dir") == null ? misc.ASC : request.getParameter("dir");
	
	if (DEBUG) {
		out.println("<br>keyId: [" + keyId + "]");
		out.println("<br>frmAction: [" + frmAction + "]");
		out.println("<br>order: [" + order + "]");
		out.println("<br>dir: [" + dir + "]");
	} 
	
	//eliminacion de registro (NA)
	String delMsg = "";
	
	int maxVersions = misc.MAX_VERSIONS_TO_LIST;
	
	sql  = "SELECT TOP " + maxVersions + " version_id id, short_name, description ";
	sql += "	FROM versions ";
	sql += "	ORDER BY start_date DESC, short_name ";

    if (DEBUG) out.println("<br>sql: [" + sql + "]");
    rs = stmt.executeQuery(sql);
%>
<form name="mainFrm" method="POST">
  <table border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td><table align="center" cellpadding="2" cellspacing="1" border="0" bgcolor="#CCCCC0">
        <tr>
          <td colspan="2" class="titulocolumna" align="center">Filtros</td>
        </tr>
        <tr>
          <td class="etiqueta">Versi&oacute;n</td>
          <td class="etiqueta_campo"><select name="versionId" class="campo_texto">
            <option value="" selected>-- Sel. --</option>
<%
	//version quemada para facilitar las cosas
	keyId = "6";
	out.println("<br>Version quemada para facilidad de desarrollo: [" + keyId + "]");

	boolean odd = false;
	int counter	= 0; 
	
	String id 	= "";
	String dsc	= "";
	
	while (rs.next()){
		id	= rs.getString("id").trim();
		dsc	= rs.getString("short_name");
		out.println("            <option value=\"" + id + "\" " + (id.equals(keyId) ? "selected": "") + ">" + dsc + "</option>");
	}
%>
          </select></td>
        </tr>
        <tr class="etiqueta_campo">
          <td colspan="2" align="center"><input name="Button" type="button"  class="boton" value="Buscar"/></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>
<%
	if (keyId.length() > 0){
		Report report = new Report(Integer.parseInt(keyId), request);
		
		report.execute();
		
		//meses de la version
		out.println("<br>[meses de la version]");
		
		MonthlyPeriod mp;
		
		for (int i = 0; i < report.getPeriods().size(); i++){
			mp = (MonthlyPeriod)report.getPeriods().elementAt(i);
			
			out.println("<br>[" + mp.getShortName() + " " + mp.getYear() + "]");
		}

		
		//Transportes y PO
		out.println("<br>[Transportes y sus OC]");
		
		Transports t;
		PurchaseOrder po;
		
		for (int i = 0; i < report.getTransports().size(); i++){
			t = (Transports)report.getTransports().elementAt(i);
			
			out.println("<br>[" + t.getShortName() + " (" + t.getPriority() + ")]");
			
			if (t.getPo() != null){
				for (int j = 0; j < t.getPo().size(); j++){
					po = (PurchaseOrder)t.getPo().elementAt(j);
					
					out.println("<br>[" + po.getCodeFull() + " cornOrigin [" + po.getCornOrigin() + "]" 
					                  + "cornTypeId [" + po.getCornTypeId() + "] monthPeriodVersionId [" + po.getMonthPeriodVersionId() + "]");
				}				
			} else {
				out.println("<br>[no hubo PO para dicho medio de transporte]");
			}
			
		}

		//Futuros
		out.println("<br>[Futuros y sus valores]");
		Futures f;
		
		for (int i = 0; i < report.getFutures().size(); i++){
			f = (Futures)report.getFutures().elementAt(i);
			
			out.println("<br>[" + f.getShortName() + " (" + f.getYear() + ")] qty [" + f.getQuantity() + "] price [" + f.getPrice() + "]");
		}
		
		//variables para control de tamaños en tabla de resultados
		int versionPeriods			= 0;
		int importedTransports		= 0;
		int allTransports			= 0;
		int futuresYears			= 0;
		ArrayList periodsPerYear	= new ArrayList(2);
		
		//conteo de los meses de la version
		versionPeriods = report.getPeriods().size();
		
		//conteo de los transportes son Importados y cuantos hay en total
		allTransports = report.getTransports().size();
		
		for (int i = 0; i < allTransports; i++){
			t = (Transports)report.getTransports().elementAt(i);
			
			if (t.isImported()){
				importedTransports++;
			}
		}
		
		//conteo de los años de futuros y los periodos de cada uno
		int lastYear	= 0;
		int periods		= 0;
		
		for (int i = 0; i < report.getFutures().size(); i++){
			f = (Futures)report.getFutures().elementAt(i);
			
			if (lastYear != f.getYear()){
				futuresYears++;
				
				if (lastYear > 0){
					periodsPerYear.add(new Integer(periods));
					
					periods = 0;
				}
				
				lastYear = f.getYear();
				periods++;
			}
		}
		
		//se agrega el ultimo bloque de conteo de periodos por añ de futuros
		periodsPerYear.add(new Integer(periods));
		
		periodsPerYear.trimToSize();
		
		//conteo de los periodos de cada 
		
		

%>
      <div class="frame_hs" id="theFrame">
        <table border="0" align="center" cellpadding="2" cellspacing="1">
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td colspan="<%=(importedTransports * 2) %>" align="center" class="cb_titulocolumna cellBorder">Motivos Importados</td>
            <td>&nbsp;</td>
            <td colspan="<%=(allTransports + 1) %>" align="center" class="cb_titulocolumna cellBorder">Compras Mton</td>
            <td>&nbsp;</td>
            <td colspan="8" align="center" class="cb_titulocolumna cellBorder">Inventario</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
<%
		//encabezados de las columnas de futuros (años)
		for (int i = 0; i < futuresYears; i++){
%>
            <td colspan="<%=(Integer)periodsPerYear.get(i) %>" align="center" class="cb_titulocolumna cellBorder">Futuros 2010</td>
            <td>&nbsp;</td>
<%			
		}
%>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
<%
		for (int i = 0; i < report.getTransports().size(); i++){
			t = (Transports)report.getTransports().elementAt(i);
			
			if (t.isImported()){
%>
            <td colspan="2" align="center" class="cb_titulocolumna cellBorder"><%=t.getShortName() %></td>
<%		
			}
		}
%>
            <td>&nbsp;</td>
<%
		for (int i = 0; i < report.getTransports().size(); i++){
			t = (Transports)report.getTransports().elementAt(i);
%>
            <td align="center" class="cb_titulocolumna cellBorder"><%=t.getShortName() %></td>
<%		
		}
%>
            <td align="center" class="cb_titulocolumna cellBorder">Total</td>
            <td>&nbsp;</td>
            <td align="center" class="cb_titulocolumna cellBorder">Inicial</td>
            <td align="center" class="cb_titulocolumna cellBorder">$/tm</td>
            <td align="center" class="cb_titulocolumna cellBorder">Compras</td>
            <td align="center" class="cb_titulocolumna cellBorder">$/tm</td>
            <td align="center" class="cb_titulocolumna cellBorder">Molienda</td>
            <td align="center" class="cb_titulocolumna cellBorder">$/tm</td>
            <td align="center" class="cb_titulocolumna cellBorder">Final</td>
            <td align="center" class="cb_titulocolumna cellBorder">$/tm</td>
            <td>&nbsp;</td>
            <td align="center" class="cb_titulocolumna cellBorder">Fut</td>
            <td align="center" class="cb_titulocolumna cellBorder">Inv. Comp.</td>
            <td align="center" class="cb_titulocolumna cellBorder">Inv. Spot</td>
            <td align="center" class="cb_titulocolumna cellBorder">Spot Local</td>
            <td>&nbsp;</td>
<%
		//periodos de los años de futuros
		lastYear = 0;

		for (int i = 0; i < report.getFutures().size(); i++){
			f = (Futures)report.getFutures().elementAt(i);
			
			//si sin diferentes (y no es el primer año, agrega separador
			if (lastYear != f.getYear() && lastYear > 0){
%>				
	            <td>&nbsp;</td>
<%
			}
			
			lastYear = f.getYear();
%>				
            <td align="center" class="cb_titulocolumna cellBorder"><%=f.getShortName() %></td>
<%
		}
%>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr class="columnadatoPar">
            <td>&nbsp;</td>
            <td>&nbsp;</td>
<!-- Transportes Importados -->
            <td colspan="<%=(importedTransports * 2) %>">&nbsp;</td>
            <td>&nbsp;</td>
<!-- Transportes Mton -->
            <td colspan="<%=(allTransports +1) %>">&nbsp;</td>
            <td>&nbsp;</td>
<!-- Inventario -->
            <td colspan="8">&nbsp;</td>
            <td>&nbsp;</td>
<!-- Inventario Futuros (columnas sin titulo) -->
            <td colspan="4">&nbsp;</td>
            <td>&nbsp;</td>
<!-- Futuros por periodos -->
<%
		//cantidades de los años de futuros
		int totalFuturesQty = 0;
		lastYear = 0;

		for (int i = 0; i < report.getFutures().size(); i++){
			f = (Futures)report.getFutures().elementAt(i);
			
			//si sin diferentes (y no es el primer año, agrega separador
			if (lastYear != f.getYear() && lastYear > 0){
%>				
	            <td>&nbsp;</td>
<%
			}
			
			lastYear = f.getYear();
			
			totalFuturesQty += f.getQuantity();
%>				
            <td align="right"><%=f.getQuantity() %></td>
<%
		}
%>
            <td>&nbsp;</td>
<!-- Total de Futuros -->
            <td align="right"><%=totalFuturesQty %></td>
            <td align="right">&nbsp;</td>
          </tr>
          <tr class="columnadatoPar">
            <td>&nbsp;</td>
            <td>&nbsp;</td>
<!-- Transportes Importados -->
            <td colspan="<%=(importedTransports * 2) %>">&nbsp;</td>
            <td>&nbsp;</td>
<!-- Transportes Mton -->
            <td colspan="<%=(allTransports +1) %>">&nbsp;</td>
            <td>&nbsp;</td>
<!-- Inventario -->
            <td colspan="8">&nbsp;</td>
            <td>&nbsp;</td>
<!-- Inventario Futuros (columnas sin titulo) -->
            <td colspan="4">&nbsp;</td>
            <td>&nbsp;</td>
<!-- Futuros por periodos -->
<%
		//ponderados de los años de futuros
		double waFuturesPrice = 0;
		lastYear = 0;

		for (int i = 0; i < report.getFutures().size(); i++){
			f = (Futures)report.getFutures().elementAt(i);
			
			//si son diferentes (y no es el primer año, agrega separador
			if (lastYear != f.getYear() && lastYear > 0){
%>				
	            <td>&nbsp;</td>
<%
			}
			
			lastYear = f.getYear();
			
			waFuturesPrice += (f.getQuantity() * f.getPrice()) / totalFuturesQty;
%>				
            <td align="right"><%=f.getPrice() %></td>
<%
		}
%>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
<!-- Total de $ ponderado de futuros -->
            <td align="right"><%=waFuturesPrice %></td>
          </tr>
<!-- Renglones de cada periodo de la version -->
<%
		for (int i = 0; i < versionPeriods; i++){
			mp = (MonthlyPeriod)report.getPeriods().elementAt(i);
%>
          <tr class="<%=((i % 2 == 0) ? "columnadatoPar" : "columnadatoNon")%> ">
            <td class="dw_etiqueta_campo cellBorder"><%=(mp.getShortName() + "&nbsp;" + mp.getYear()) %></td>
            <td><%=mp.getMonthPeriodVersionId() %>&nbsp;</td>
            <!-- codigos numericos de cada uno de los transportes de este mes -->
<%
		PurchaseOrder p;
		String poCodes	= "";
		int poQty		= 0; 

		for (int j = 0; j < report.getTransports().size(); j++){
			t = (Transports)report.getTransports().elementAt(j);
			
			if (t.isImported()){
				for (int k = 0; k < t.getPo().size(); k++){
					p = (PurchaseOrder)t.getPo().elementAt(k);
					
					if (mp.getMonthPeriodVersionId() == p.getMonthPeriodVersionId()){
						poCodes += "" + p.getCodeNumber() + ",&nbsp;";
						poQty++;
					}
				}
%>
            <td class="cellBorder"><%=(poCodes.length() > 0 ? poCodes.substring(0, poCodes.length() - 7) : "") %></td>
            <td align="right" class="cellBorder"><%=(poQty > 0 ? ("" + poQty) : "&nbsp;") %></td>
<%
				poCodes = "";
				poQty = 0;
			}
		}
%>
            <td>&nbsp;</td>
            <!-- Compras Mton por cada transporte -->
<%
		float periodTransportCapacity	= 0;
		float periodTotalCapacity		= 0;

		for (int j = 0; j < report.getTransports().size(); j++){
			t = (Transports)report.getTransports().elementAt(j);
			
			for (int k = 0; k < t.getPo().size(); k++){
				p = (PurchaseOrder)t.getPo().elementAt(k);
				
				if (mp.getMonthPeriodVersionId() == p.getMonthPeriodVersionId()){
					periodTransportCapacity += p.getCapacity();
				}
			}
%>
            <td align="right" class="cellBorder"><%=periodTransportCapacity %></td>
<%
			periodTotalCapacity 	+= periodTransportCapacity;
			periodTransportCapacity	= 0;
		}
%>
            <td align="right" class="cellBorder"><%=periodTotalCapacity %></td>
            <td>&nbsp;</td>
            <td align="right" class="cellBorder">239</td>
            <td align="right" class="cellBorder">255</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right" class="cellBorder">91</td>
            <td>&nbsp;</td>
            <td align="right" class="cellBorder">43</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right" class="cellBorder">134</td>
            <td align="right" class="cellBorder">4.2</td>
          </tr>
<%
		}
%>
          <tr class="etiqueta_campo_center">
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td width="0" align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right" class="cellBorder">180</td>
            <td>&nbsp;</td>
            <td align="right" class="cellBorder">43</td>
            <td align="right" class="cellBorder">33</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
          </tr>
          <tr class="etiqueta_campo_center">
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td colspan="2" align="right" class="cellBorder">18</td>
            <td colspan="2" align="right" class="cellBorder">12</td>
            <td colspan="2" align="right" class="cellBorder">6</td>
            <td colspan="2" align="right" class="cellBorder">3</td>
            <td>&nbsp;</td>
            <td align="right" class="cellBorder">560</td>
            <td align="right" class="cellBorder">...</td>
            <td align="right" class="cellBorder">...</td>
            <td align="right" class="cellBorder">...</td>
            <td align="right" class="cellBorder">...</td>
            <td align="right" class="cellBorder">...</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right" class="cellBorder">0</td>
            <td>&nbsp;</td>
            <td align="right" class="cellBorder">0</td>
            <td align="right" class="cellBorder">2</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
          </tr>
          <tr class="etiqueta_campo_center">
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td colspan="2" align="right">&nbsp;</td>
            <td colspan="2" align="right">&nbsp;</td>
            <td colspan="2" align="right">&nbsp;</td>
            <td colspan="2" align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
          </tr>
          <tr class="etiqueta_campo_center">
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td colspan="2" align="right">&nbsp;</td>
            <td colspan="2" align="right">&nbsp;</td>
            <td colspan="2" align="right">&nbsp;</td>
            <td colspan="2" align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right" class="cellBorder">3.3</td>
            <td>&nbsp;</td>
            <td align="right" class="cellBorder">4.7</td>
            <td align="right" class="cellBorder">5.1</td>
            <td align="right" class="cellBorder">...</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right" class="cellBorder">4.3</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td align="right">&nbsp;</td>
          </tr>
        </table>
      </div>
        <br>
        <br>
        <table border="0" align="center" cellpadding="2" cellspacing="1">
          <tr>
            <td>&nbsp;</td>
            <td rowspan="2" align="center" valign="bottom" class="titulocolumna cellBorder">Mton</td>
            <td colspan="2" align="center" class="titulocolumna cellBorder">USD / Bushel</td>
            <td rowspan="2" align="center" valign="bottom" class="titulocolumna cellBorder">USD/Ton</td>
            <td rowspan="2" align="center" valign="bottom" class="titulocolumna cellBorder">MMUsd</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td align="center" class="titulocolumna cellBorder">CBOT Price</td>
            <td align="center" class="titulocolumna cellBorder">Basis</td>
          </tr>
          <tr class="etiqueta_campo_center">
            <td class="cellBorder">Inicial</td>
            <td align="right" class="cellBorder">238.9</td>
            <td align="right" class="cellBorder">4.8</td>
            <td align="right" class="cellBorder">1.65</td>
            <td align="right" class="cellBorder">255</td>
            <td align="right" class="cellBorder">60.9</td>
          </tr>
          <tr class="etiqueta_campo_center">
            <td class="cellBorder">Futuros</td>
            <td align="right" class="cellBorder">640.6</td>
            <td align="right" class="cellBorder">5.5</td>
            <td align="right" class="cellBorder">1.65</td>
            <td align="right" class="cellBorder">280</td>
            <td align="right" class="cellBorder">179.1</td>
          </tr>
          <tr class="etiqueta_campo_center">
            <td class="cellBorder">Propiedad</td>
            <td align="right" class="cellBorder">879.5</td>
            <td align="right" class="cellBorder">5.3</td>
            <td align="right" class="cellBorder">...</td>
            <td align="right" class="cellBorder">...</td>
            <td align="right" class="cellBorder">...</td>
          </tr>
          <tr class="etiqueta_campo_center">
            <td class="cellBorder">Open Corn</td>
            <td align="right" class="cellBorder">719.5</td>
            <td align="right" class="cellBorder">3.6</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
          </tr>
          <tr class="etiqueta_campo_center">
            <td class="cellBorder">Molienda</td>
            <td align="right" class="cellBorder">1,599.0</td>
            <td align="right" class="cellBorder">4.5</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
            <td align="right" class="cellBorder">&nbsp;</td>
          </tr>
        </table>
        <br>
        <br>
        <table border="0" align="center" cellpadding="2" cellspacing="1">
          <tr>
            <td class="titulocolumna cellBorder">Customer Corn Req.</td>
            <td>&nbsp;</td>
            <td class="titulocolumna cellBorder">656</td>
            <td>&nbsp;</td>
            <td align="right" class="titulocolumna cellBorder">134%</td>
            <td class="dw_etiqueta_campo cellBorder">vs. Propiedad</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right" class="titulocolumna cellBorder">98%</td>
            <td class="dw_etiqueta_campo cellBorder">vs. Futuros</td>
          </tr>
        </table>
        <br>
        <br>
        <table border="0" align="center" cellpadding="2" cellspacing="2">
          <tr>
            <td><input name="btnExcel" type="submit" class="boton" id="btnExcel" value="Excel"></td>
          </tr>
        </table> 
<%
	} else {		//termina validacion de version a consultar
		out.println("<br> Favor de seleccionar una versión");
	}
%>
        </td>
    </tr>
  </table>
</form>
<%
}catch (Exception e){
	String errorMsg = "";
	errorMsg  = "            <table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">";
	errorMsg += "              <tr>";
	errorMsg += "                <td class=\"errorMsg\">";
	
	errorMsg += "                  Error al procesar el registro";
	errorMsg += "                  <br>Mensaje de error: " + e.getMessage();

	errorMsg += "                </td>";
	errorMsg += "              </tr>";
	errorMsg += "            </table>";
	
	out.println(misc.ERROR + "|" + errorMsg);
} finally {
    try { conn.close(); } catch (Exception e) {}
    try { stmt.close(); } catch (Exception e) {}
    try { rs.close();   } catch (Exception e) {}
}
%>

</body>
</html>